package fr.ece.ing4.ams;

import java.util.HashSet;
import java.util.Set;

public class SystemManager {

	private static Set<Airport> airport = new HashSet<Airport> ();

	private SystemManager() {
		super();
	}

	/**
	 * Returns an instance of Airport
	 * @param code airport code must be 3 chars long
	 * @return the new airport
	 * @throws AMSexeception 
	 */
	
	public static Airport createAiport(String code) throws AMSexeception{
		
		if(code.length() != 3)
		{
			throw new IllegalArgumentException("code must be 3 chars long");
		}
		Airport ap = new Airport(code);
		if (!airport .add(ap)){
			ap = null;
			throw new AMSexeception("Airport already exists");
		}
		
		return ap;
	}
	
	/**
	 * Returns an instance of Airport
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			Airport cdg  = createAiport("CDG");
			//Airport cdg1  = createAiport("CDG");
			System.out.println(airport);
		} catch (AMSexeception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		

	}

}
